#打印小票
def printShopCart(shopCart,shopCartNum):
    total=0
    print("----------------购物车表----------------")
    # print("商品名称    商品数量    商品金额")
    print("|{:^10}|{:^10}|{:^10}|".format("商品名称", "商品数量", "商品金额"))
    for  item in shopCart.items():
        # print("%-10s%-10s%-4s"%(item[0],shopCartNum[item[0]],item[1]*shopCartNum[item[0]]))
        print("|{:^10}|{:^10}|{:^10}|".format(item[0], shopCartNum[item[0]], item[1]*shopCartNum[item[0]]))
# 遍历购物车表判断是否有商品
def judgeCart(shopName,goodsList,shopCart,shopCartNum):
    global money
    flag=0
    for item in goodsList.items():
        goodsName = item[0]
        goodsMoney = item[1]
        if shopName == goodsName:
            flag=1
            if money >= goodsMoney:
                money -= goodsMoney
                if shopName in shopCart:
                    shopCart[shopName] += goodsMoney
                    shopCartNum[shopName]+=1
                    break
                else:
                    shopCart.setdefault(goodsName, goodsMoney)
                    shopCartNum[shopName] += 1
                    break
            else:
                print("穷鬼，钱不够！请到其他超市购买！")
                break
        elif shopName == 'Q' or shopName == 'q':
            printShopCart(shopCart,shopCartNum)
            exit(0)
    if flag==0:
        print("没有这个商品，别瞎弄！")

if __name__ == '__main__':
    #余额
    money = 100
    #商品表
    goodsList = {"AD钙奶": 5, "旺仔小馒头": 5, "唐僧肉": 5, "玩具车": 80, "玩具飞机": 99}
    #购物车表
    shopCart = {}
    #购买商品数量
    shopCartNum = {"AD钙奶": 0, "旺仔小馒头": 0, "唐僧肉": 0, "玩具车": 0, "玩具飞机": 0}
    while(True):
        shopName=input("请输入购买的商品\n").strip()
        judgeCart(shopName,goodsList,shopCart,shopCartNum)
